<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
	//Truy cap vao server
	@$connection = mysql_pconnect('localhost', 'root', '');
	if(!$connection)
	{
		echo "Server now is not avaiable, please try later";
	}
	
	//Truy cap vao database
	@$db = mysql_select_db('studial');
	if(!$db)
	{
		echo "An error has occured, please try later";
	}
	
	//Lay bien tu trong tao course
	$course_name = addslashes(trim($_POST['coursename']));
	$description = addslashes(trim($_POST['description']));
	$startdate  = addslashes(trim($_POST['startdate']));
	$duration = addslashes(trim($_POST['duration']));
	$username = $_COOKIE['username']; //gia dinh ten user da duoc luu trong cookie
	
	//Lay id cua user
	$query = "select * from `user` where `userid`='".$username."'";
	$result = mysql_query($query);
	$rows = mysql_fetch_array($result);
	$userid = $rows['userid'];
	
	//Tao course
	$query = "insert into `courses` (`coursename`, `description`, `managerid`, `startdate`, `duration`) values('".$course_name."', '".$description."', '".$userid."', '".$startdate."', '".$duration."');";
	$result = mysql_query($query);
	if(!$query)
	{
		echo "An error has occured, no course has create, please try later";	
	}
	else
	{
		echo "Create successfully";
	}
?>
</body>
</html>